//
//  FWMViewController.m
//  DaJiHui
//
//  Created by Hao on 2017/8/25.
//  Copyright © 2017年 Hao. All rights reserved.
//

#import "FWMViewController.h"

@interface FWMViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *myTableView;
@property(nonatomic,assign)NSInteger clickNum;
@property(nonatomic,assign)NSInteger getClickNum;
@end

@implementation FWMViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeBaseUI];
    self.view.backgroundColor= [UIColor whiteColor];
    // Do any additional setup after loading the view.
}
- (void)makeBaseUI{
    [self.view addSubview:self.myTableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"这是第%ld分组的第%ld个Cell",indexPath.section,indexPath.row];
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, ZTY_SCREEN_WIDTH, 30)];
    label.tag = section;
    label.text = [NSString stringWithFormat:@"这是第%ld分组",section];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    label.userInteractionEnabled = YES;
    [label addGestureRecognizer:tap];
    return label;
}
-(void)tap:(UITapGestureRecognizer *)tap{
    self.clickNum = tap.view.tag;
    if (self.clickNum == self.getClickNum) {
        self.clickNum = 180;
    }
    [self.myTableView reloadData];
    self.getClickNum = self.clickNum;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr = @[@"2",@"4",@"6",@"8",@"10"];
    if (self.clickNum == 180) {
        return 0;
    }else{
        if (self.clickNum == section) {
            
            return [arr[section] intValue];
        }else{
            
            return 0;
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}

- (UITableView *)myTableView{
    
    if (_myTableView == nil) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ZTY_SCREEN_WIDTH, ZTY_SCREEN_HEIGHT-49-64) style:UITableViewStyleGrouped];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    
    return _myTableView;
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
